<?php
class Administrator_ZhuantiController extends Zend_Controller_Action
{
	public function init()
	{
		$member=new CMember();
		if(!$member->isUser($this->_request->getModuleName(),$this->_request->getControllerName())){	
			$this->_redirect(MY_URL.'/administrator-auth-login');
		}
	}
	
	public function preDispatch()
	{
		$this->getHelper ('layout')->setLayout('framelayout');
		$this->view->addHelperPath(MY_ROOT.'/vhelpers');
		Zend_Controller_Action_HelperBroker::addPath(MY_ROOT.'/chelpers');
	}
	
	public function indexAction()
	{
		$zhuanti = new CZhuanti();
		$zhuantiList = $zhuanti->fetchAll();
		$this->view->zhuantiList = $zhuantiList;
	}
	
	public function addAction()
	{
		if ($this->getRequest()->isPost()) {
			$this->getHelper('viewRenderer')->setNoRender();
			$thisArray=$this->_request->getParams();
			$filters = array(
	    		'*'   => 'StringTrim'
			);
			$validators = array();
			$input = new Zend_Filter_Input($filters, $validators, $thisArray);
			/*插入到条目表 start*/
			$zhuanti = new CZhuanti();			
			$data=array(
							'name'=>$input->name,							
							'seo_title'=>$input->title,
							'seo_description'=>$input->description,
							'seo_keywords'=>$input->keywords,
							'itemids'=>$input->itemids
						 );	
			$zhuanti->add($data);
			/*插入到公告表 end*/			
			$this->view->showMsg("添加!",'administrator-zhuanti');
		} else {
			
		}
	}
	
	public function editAction()
	{
		if ($this->getRequest()->isPost()) {
			$this->getHelper('viewRenderer')->setNoRender();
			$paramArray=$this->_request->getParams();
			$zhuantiId=$paramArray['id'];
			$filters = array(
	    		'*'   => 'StringTrim'
			);
			$validators = array(
			);
			$input = new Zend_Filter_Input($filters, $validators, $paramArray);	
			/*修改条目表 start*/
			$zhuanti = new CZhuanti();			
			$data=array(
							'name'=>$input->name,							
							'seo_title'=>$input->title,
							'seo_description'=>$input->description,
							'seo_keywords'=>$input->keywords,
							'itemids'=>$input->itemids
						 );	
			$zhuanti->edit($data, $zhuantiId);
			/*修改公告表 end*/
			$this->view->showMsg("修改成功!",'administrator-zhuanti');
			
		} else {
			$zhuantiId=$this->_request->getParam('id');
	    	$zhuanti = new CZhuanti();
	    	$this->view->zhuanti = $zhuanti->getById($zhuantiId);
		}
	}
	
	public function deleteAction()
	{
		$this->_helper->viewRenderer->setNoRender();
    	$itemid = $this->_request->getParam('id');
    	
    	$zhuanti = new CZhuanti();
    	$zhuanti->delete($itemid);    	
    	
    	$this->view->showMsg('删除成功!');
	}
}